package com.bestcem.xm.survey.mq.send.biz.impl;

import com.alibaba.fastjson.JSONObject;
import com.bestcem.xm.common.core.config.mq.XmMessageProducer;
import com.bestcem.xm.common.core.constant.StreamMqBinderConstants;
import com.bestcem.xm.survey.mq.dto.CreateQuotaDto;
import com.bestcem.xm.survey.mq.dto.TicketNotificationTriggerDto;
import com.bestcem.xm.survey.mq.send.biz.SurveyMessageSendService;
import com.fasterxml.jackson.core.JsonProcessingException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class SurveyMessageSendServiceImpl implements SurveyMessageSendService {

    private final XmMessageProducer messageProducer;

    public SurveyMessageSendServiceImpl(XmMessageProducer messageProducer) {
        this.messageProducer = messageProducer;
    }

    @Override
    public void surveyRespondentOpenSend(JSONObject dto) {
        log.info("[survey] surveyRespondentOpenSend 发送消息内容={}", dto.toJSONString());
        try {
            messageProducer.send(StreamMqBinderConstants.SURVEY_RESPONDENT_OPEN, dto);
        } catch (JsonProcessingException e) {
            log.error("[survey]打开问卷消息:{}", dto.toJSONString(), e);
        }
    }

    @Override
    public void surveyAddQuoteSend(CreateQuotaDto dto) {
        log.info("[survey] surveyAddQuoteSend 发送消息内容={}", JSONObject.toJSONString(dto));
        try {
            messageProducer.send(StreamMqBinderConstants.SURVEY_ADD_QUOTE, dto);
        } catch (JsonProcessingException e) {
            log.error("[survey]新增配额消息:{}", JSONObject.toJSONString(dto), e);
        }
    }

    @Override
    public void surveyPopQuoteSend(CreateQuotaDto dto) {
        log.info("[survey] surveyPopQuoteSend 发送消息内容={}", JSONObject.toJSONString(dto));
        try {
            messageProducer.send(StreamMqBinderConstants.SURVEY_POP_QUOTE, dto);
        } catch (JsonProcessingException e) {
            log.error("[survey]删除配额消息:{}", JSONObject.toJSONString(dto), e);
        }
    }

    @Override
    public void surveyRespondentStatusChangedSend(JSONObject dto) {
        log.info("[survey] surveyRespondentStatusChangedSend 发送消息内容={}", dto.toJSONString());
        try {
            messageProducer.send(StreamMqBinderConstants.SURVEY_RESPONDENT_STATUS_CHANGED, dto);
        } catch (JsonProcessingException e) {
            log.error("[survey]答卷状态变化消息:{}", dto.toJSONString(), e);
        }
    }

    @Override
    public void notificationTriggerSend(TicketNotificationTriggerDto dto) {
        log.info("[survey] notificationTriggerSend 发送消息内容={}", JSONObject.toJSONString(dto));
        try {
            messageProducer.send(StreamMqBinderConstants.NOTIFICATION_TRIGGER_OUT, dto);
        } catch (JsonProcessingException e) {
            log.error("[survey] notificationTriggerSend消息:{}", JSONObject.toJSONString(dto), e);
        }
    }

    @Override
    public void surveyRespondentModifySend(JSONObject dto) {
        log.info("[survey] surveyRespondentModifySend 发送消息内容={}", dto.toJSONString());
        try {
            messageProducer.send(StreamMqBinderConstants.SURVEY_RESPONDENT_MODIFY, dto);
        } catch (JsonProcessingException e) {
            log.error("[survey] surveyRespondentModifySend消息:{}", dto.toJSONString(), e);
        }
    }

    @Override
    public void memberFootprintSaveSend(JSONObject dto) {
        log.info("[survey] memberFootprintSaveSend 发送消息内容={}", dto.toJSONString());
        try {
            messageProducer.send(StreamMqBinderConstants.MEMBER_FOOT_PRINT_SAVE_OUT, dto);
        } catch (JsonProcessingException e) {
            log.error("[survey] memberFootprintSaveSend消息:{}", dto.toJSONString(), e);
        }
    }

    @Override
    public void surveyRespondentUnfinishSend(JSONObject dto) {
        log.info("[survey] surveyRespondentUnfinishSend 发送消息内容={}", dto.toJSONString());
        try {
            messageProducer.send(StreamMqBinderConstants.SURVEY_RESPONDENT_UNFINISH, dto);
        } catch (JsonProcessingException e) {
            log.error("[survey] surveyRespondentUnfinishSend消息:{}", dto.toJSONString(), e);
        }
    }

    @Override
    public void surveyRespondentSubmitSend(JSONObject dto) {
        log.info("[survey] surveyRespondentSubmitSend 发送消息内容={}", dto.toJSONString());
        try {
            messageProducer.send(StreamMqBinderConstants.SURVEY_RESPONDENT_SUBMIT, dto);
        } catch (JsonProcessingException e) {
            log.error("[survey] surveyRespondentSubmitSendd消息:{}", dto.toJSONString(), e);
        }
    }

    @Override
    public void surveyRespondentSyncSend(JSONObject dto) {
        log.info("[survey] surveyRespondentSyncSend 发送消息内容={}", dto.toJSONString());
        try {
            messageProducer.send(StreamMqBinderConstants.SURVEY_RESPONDENT_SYNC, dto);
        } catch (JsonProcessingException e) {
            log.error("[survey] surveyRespondentSyncSend:{}", dto.toJSONString(), e);
        }
    }
}
